/**
 * Copyright: Copyright (c) 2018
 * Company:
 *
 * @author XueWei
 * @date 2018年8月30日 下午1:13:08
 * @version V1.0
 */
package com.smartcommunity.service.village.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smartcommunity.bean.entity.Village;
import com.smartcommunity.bean.enumeration.ResultCode;
import com.smartcommunity.bean.enumeration.SymbolEnum;
import com.smartcommunity.bean.model.Pager;
import com.smartcommunity.bean.model.Result;
import com.smartcommunity.dao.village.RealCompanyDao;
import com.smartcommunity.dao.village.VillageDao;
import com.smartcommunity.entity.village.RealCompany;
import com.smartcommunity.entity.village.RealCompanyPeople;
import com.smartcommunity.entity.village.dto.UpdateRealCompanyPeopleDto;
import com.smartcommunity.service.businessCircle.RealCompanyService;
import com.smartcommunity.utils.IDCardUtil;
import com.smartcommunity.utils.ToolString;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

import static org.apache.commons.lang3.StringUtils.*;

/**
 * @version V1.0
 * @ClassName: RealCompanyServiceImpl
 * @Description: 实有单位service接口实现
 * @author: minsheng
 * @Date: 2019/3/5 14:04
 * @Company:
 */
@Service
@Slf4j
public class RealCompanyServiceImpl implements RealCompanyService {

    @Autowired
    private RealCompanyDao realCompanyDao;
    @Autowired
    private VillageDao villageDao;

    /**
     * @Description: 获取实有单位列表
     * @param: [map, currentPage, pageSize]
     * @return: com.smartcommunity.base.bean.Pager<com.smartcommunity.entity.face.RealCompany>
     * @author: minsheng
     * @date: 2019/1/4 10:21
     */
    @Override
    public Pager<RealCompany> pageRealCompanies(Map<String, Object> map, int currentPage, int pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        List<RealCompany> realCompanyList = realCompanyDao.listRealCompanies(map);
        if(!CollectionUtils.isEmpty(realCompanyList)) {
            List<Map<String, Object>> realCompanyPeopleCountList = realCompanyDao.listRealCompaniesPeopleCount(map);
            for (RealCompany realCompany : realCompanyList) {
                for (Map<String, Object> realCompanyPeopleCount : realCompanyPeopleCountList) {
                    if (realCompany.getCompanyId().equals(realCompanyPeopleCount.get("companyid"))) {
                        if (null != realCompanyPeopleCount.get("peopleCount")) {
                            realCompany.setPeopleCount(Integer.valueOf(realCompanyPeopleCount.get("peopleCount").toString()));
                            break;
                        }
                    }
                }
                if (null == realCompany.getPeopleCount()) {
                    realCompany.setPeopleCount(0);
                }
            }
        }
        int totalNum = (int) ((Page<RealCompany>) realCompanyList).getTotal();
        Pager<RealCompany> realCompanyPeoplePager = new Pager<>(currentPage, pageSize, totalNum);
        realCompanyPeoplePager.setList(realCompanyList);
        return realCompanyPeoplePager;
    }

    /**
     * @Description: 获取实有单位从业人员列表
     * @param: [map, currentPage, pageSize]
     * @return: com.smartcommunity.base.bean.Pager<com.smartcommunity.entity.face.RealCompany>
     * @author: minsheng
     * @date: 2019/1/4 10:21
     */
    @Override
    public Pager<RealCompanyPeople> pageRealCompanyPeoples(Map<String, Object> map, int currentPage, int pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        List<RealCompanyPeople> realCompanyPeopleList = realCompanyDao.getRealCompanyPeopleList(map);
        int totalNum = (int) ((Page<RealCompanyPeople>) realCompanyPeopleList).getTotal();
        Pager<RealCompanyPeople> realCompanyPeoplePager = new Pager<>(currentPage, pageSize, totalNum);
        realCompanyPeoplePager.setList(realCompanyPeopleList);
        return realCompanyPeoplePager;
    }


    @Override
    public Result getRealCompany(String id) {
        RealCompany realCompany = realCompanyDao.getRealCompany(id);
        return Result.ok(realCompany);
    }

    /**
     * 新增实有单位
     *
     * @param realCompany
     * @return
     */
    @Override
    public Result insertRealCompany(RealCompany realCompany) {
        JSONObject jsonObject = new JSONObject();
        //判断小区编号是否有值
        if (StringUtils.isEmpty(realCompany.getVillageCode())) {
            return Result.error(ResultCode.MIS_VALID_PARAM);
        }
        //判断单位名称是否有值
        if (StringUtils.isEmpty(realCompany.getCompanyName())) {
            return Result.error(ResultCode.MIS_VALID_PARAM);
        }
        // 判断单位名称是否唯一
        Map<String, Object> paramMap = new HashMap<>(1);
        paramMap.put("fullName", realCompany.getCompanyName());
        List<RealCompany> list = realCompanyDao.listRealCompanies(paramMap);
        if (!CollectionUtils.isEmpty(list)) {
            return Result.error(ResultCode.COMPANY_NAME_EXSIT);
        }

        realCompany.setCompanyId(UUID.randomUUID().toString().replace("-", ""));
        realCompanyDao.insertRealCompany(realCompany);

        return Result.ok();
    }

    /**
     * 修改实有单位
     *
     * @param paramMap
     * @return
     */
    @Override
    public Result updateRealCompany(Map<String, Object> paramMap) {
        // 判断单位名称是否唯一
        Map<String, Object> map = new HashMap<>(2);
        //精准查询
        map.put("fullName", paramMap.get("companyName"));
        //并且不等于当前id
        map.put("noId", paramMap.get("companyId"));
        List<RealCompany> list = realCompanyDao.listRealCompanies(map);
        if (!CollectionUtils.isEmpty(list)) {
            return Result.error(ResultCode.COMPANY_NAME_EXSIT);
        }

        //判断实有单位id获取单位信息
        map = new HashMap<>(1);
        map.put("companyId", paramMap.get("companyId"));
        List<RealCompany> realCompanyList = realCompanyDao.listRealCompanies(map);
        if (CollectionUtils.isEmpty(realCompanyList)) {
            return Result.error(ResultCode.COMPANY_NOT_EXSIT);
        }
        RealCompany realCompany = realCompanyList.get(0);
        realCompany.setCompanyName(String.valueOf(paramMap.get("companyName")));
        realCompany.setVillageCode(String.valueOf(paramMap.get("villageCode")));
        realCompany.setCompanyAddress(String.valueOf(paramMap.get("companyAddress")));
        realCompany.setCompanyPic(String.valueOf(paramMap.get("companyPic")));
        realCompanyDao.updateRealCompany(realCompany);
        return Result.ok();
    }

    public Result updateRealCompany(RealCompany realCompany) {
        // 判断单位名称是否唯一
        Map<String, Object> map = new HashMap<>(2);
        //精准查询
        map.put("fullName", realCompany.getCompanyName());
        //并且不等于当前id
        map.put("noId", realCompany.getCompanyId());
        List<RealCompany> list = realCompanyDao.listRealCompanies(map);
        if (!CollectionUtils.isEmpty(list)) {
            return Result.error(ResultCode.COMPANY_NAME_EXSIT);
        }

        //判断实有单位id获取单位信息
        map = new HashMap<>(1);
        map.put("companyId", realCompany.getCompanyId());
        List<RealCompany> realCompanyList = realCompanyDao.listRealCompanies(map);
        if (CollectionUtils.isEmpty(realCompanyList)) {
            return Result.error(ResultCode.COMPANY_NOT_EXSIT);
        }
        realCompanyDao.updateRealCompany(realCompany);
        return Result.ok();
    }

    /**
     * 删除实有单位
     *
     * @param companyId
     * @return
     */
    @Override
    public Result deleteRealCompany(String companyId) {
        JSONObject jsonObject = new JSONObject();
        // 判断要删除的单位下是否有从业人员
        Map<String, Object> paramMap = new HashMap<>(16);
        String[] companyIds = companyId.split(",");
        for (int i = 0; i < companyIds.length; i++) {
            paramMap.put("companyId", companyIds[i]);
            List<RealCompanyPeople> realCompanyPeopleList = realCompanyDao.getRealCompanyPeopleList(paramMap);
            if (!CollectionUtils.isEmpty(realCompanyPeopleList)) {
                return Result.error(ResultCode.COMPANY_HAVA_PEOPLE);
            }
        }

        paramMap = new HashMap<>(1);
        paramMap.put("companyId", companyId);
        realCompanyDao.deleteRealCompany(paramMap);
        return Result.ok();
    }

    /**
     * @Description: 更新公司经纬度
     * @param: [realCompany]
     * @return: void
     * @author: minsheng
     * @date: 2019/1/5 11:09
     */
    @Override
    public void updateCompanyCoord(RealCompany realCompany) {
        realCompanyDao.updateCompanyCoord(realCompany);
    }

    /**
     * 新增从业人员
     *
     * @param realCompanyPeople
     * @return
     */
    @Override
    public Result insertRealCompanyPeople(RealCompanyPeople realCompanyPeople) {
        JSONObject jsonObject = new JSONObject();
        // 判断所属单位是否为空
        if (StringUtils.isEmpty(realCompanyPeople.getCompanyId())) {
            return Result.error(ResultCode.MIS_VALID_PARAM);
        }
        // 判断小区编号是否为空
        if (StringUtils.isEmpty(realCompanyPeople.getVillageCode())) {
            return Result.error(ResultCode.MIS_VALID_PARAM);
        }
        // 判断小区编号是否有效
        Village village = villageDao.getVillage(realCompanyPeople.getVillageCode());
        if (StringUtils.isEmpty(village.getVillageName())) {
            return Result.error(ResultCode.VILLAGE_CODE_NOT_EXSIT);
        }
        // 判断姓名是否为空
        if (StringUtils.isEmpty(realCompanyPeople.getName())) {
            return Result.error(ResultCode.MIS_VALID_PARAM);
        }
        // 判断证件号是否为空
        if (StringUtils.isNotEmpty(realCompanyPeople.getCredentialNo())) {
            if (length(realCompanyPeople.getCredentialNo())>18) {
                return Result.error(ResultCode.PEOPLE_CREDENTIALNO_ERROR);
            }
        }

        // 判断人员信息是否存在
        Map<String, Object> paramMap = new HashMap<>(3);
        paramMap.put("name",realCompanyPeople.getName() );
        paramMap.put("credentialNo", realCompanyPeople.getCredentialNo());
        paramMap.put("companyId", realCompanyPeople.getCompanyId());
        List<RealCompanyPeople> realCompanyPeopleList = realCompanyDao.checkInsertCompanyPeople(paramMap);
        if (!CollectionUtils.isEmpty(realCompanyPeopleList)) {
            return Result.error(ResultCode.COMPANY_PEOPLE_EXSIT);
        }
        realCompanyDao.insertRealCompanyPeople(realCompanyPeople);
        return Result.ok();
    }

    /**
     * 更新从业人员
     * @return
     */
    /**
     * 更新从业人员
     *
     * @param paramMap
     * @return
     */
    @Override
    public Result updateRealCompanyPeople(Map<String, Object> paramMap) {
        // 判断人员信息是否存在
        Map<String, Object> map = new HashMap<>(3);
        map.put("credentialNo", ToolString.parseSeparater(paramMap.get("credentialNo").toString(),SymbolEnum.COMMA.toString(),SymbolEnum.QUATATION.toString()));
        map.put("companyId", paramMap.get("companyId"));
        List<RealCompanyPeople> tempList = realCompanyDao.getRealCompanyPeopleList(map);
        if (CollectionUtils.isEmpty(tempList)) {
            return Result.error(ResultCode.COMPANY_PEOPLE_NOT_EXSIT);
        }
        //根据id获取从业人员信息
        map.clear();
        map.put("id", paramMap.get("id"));
        List<RealCompanyPeople> realCompanyPeopleList = realCompanyDao.getRealCompanyPeopleList(map);
        if (!CollectionUtils.isEmpty(realCompanyPeopleList)) {
            RealCompanyPeople realCompanyPeople = realCompanyPeopleList.get(0);
            if (StringUtils.trimToNull(String.valueOf(paramMap.get("name"))) != null) {
                realCompanyPeople.setName(String.valueOf(paramMap.get("name")));
            }
            if (StringUtils.trimToNull(String.valueOf(paramMap.get("sex"))) != null) {
                realCompanyPeople.setSex(String.valueOf(paramMap.get("sex")));
            }
            if (StringUtils.trimToNull(String.valueOf(paramMap.get("phone"))) != null) {
                realCompanyPeople.setPhone(String.valueOf(paramMap.get("phone")));
            }
            if (StringUtils.trimToNull(String.valueOf(paramMap.get("credentialNo"))) != null) {
                realCompanyPeople.setCredentialNo(String.valueOf(paramMap.get("credentialNo")));
            }
            realCompanyDao.updateRealCompanyPeople(realCompanyPeople);
        }
        return Result.ok();
    }


    @Override
    public Result updateRealCompanyPeopleNew(UpdateRealCompanyPeopleDto updateRealCompanyPeople) {
        // 判断人员信息是否存在
        Map<String, Object> map = new HashMap<>(3);
        RealCompanyPeople realpe = realCompanyDao.getRealCompanyPeople(updateRealCompanyPeople.getId());
        if (realpe == null) {
            return Result.error(ResultCode.COMPANY_PEOPLE_NOT_EXSIT);
        }
       realCompanyDao.updateRealCompanyPeopleNew(updateRealCompanyPeople);
        return Result.ok();
    }

    /**
     * 删除从业人员
     *
     * @param id
     * @return
     */
    @Override
    public Result deleteRealCompanyPeople(String id) {
        Map<String, Object> paramMap = new HashMap<>(1);
        paramMap.put("id", id);
        realCompanyDao.deleteRealCompanyPeople(paramMap);
        return Result.ok();
    }

    @Override
    public Result getRealCompanyPeople(String id) {
        RealCompanyPeople  realCompanyPeople = realCompanyDao.getRealCompanyPeople(id);
        return  Result.ok(realCompanyPeople);
    }


    @Override
    public int countRealCompanies(Map<String, Object> map) {
        int i;
        i = realCompanyDao.countRealCompanies(map);
        return i;
    }

    @Override
    public Map<String, Object> avgCount(Map<String, Object> params) {
        Map<String, Object> resultMap = new HashMap<>(16);
        Map<String, Object> map;
        List<RealCompanyPeople> list = null;
        List<Map<String, Object>> mapList = null;
        try {
            list = realCompanyDao.getRealCompanyPeopleList(params);
        } catch (Exception e) {
            log.error("查询数据库异常：" + e.getMessage());
        }
        AtomicReference<Integer> age1 = new AtomicReference<>(0);
        AtomicReference<Integer> age2 = new AtomicReference<>(0);
        AtomicReference<Integer> age3 = new AtomicReference<>(0);
        AtomicReference<Integer> age4 = new AtomicReference<>(0);

        AtomicReference<Integer> hj = new AtomicReference<>(0);
        AtomicReference<Integer> jw = new AtomicReference<>(0);
        AtomicReference<Integer> wl = new AtomicReference<>(0);


        AtomicReference<Integer> man = new AtomicReference<>(0);
        AtomicReference<Integer> woman = new AtomicReference<>(0);
        AtomicReference<Integer> other = new AtomicReference<>(0);

        AtomicReference<Integer> beijing = new AtomicReference<>(0);
        AtomicReference<Integer> tianjin = new AtomicReference<>(0);
        AtomicReference<Integer> hebei = new AtomicReference<>(0);
        AtomicReference<Integer> shanx = new AtomicReference<>(0);
        AtomicReference<Integer> nmg = new AtomicReference<>(0);
        AtomicReference<Integer> liaoning = new AtomicReference<>(0);
        AtomicReference<Integer> jilin = new AtomicReference<>(0);
        AtomicReference<Integer> hlj = new AtomicReference<>(0);
        AtomicReference<Integer> shanghai = new AtomicReference<>(0);
        AtomicReference<Integer> jiangsu = new AtomicReference<>(0);
        AtomicReference<Integer> zhejiang = new AtomicReference<>(0);
        AtomicReference<Integer> anhui = new AtomicReference<>(0);
        AtomicReference<Integer> fujian = new AtomicReference<>(0);
        AtomicReference<Integer> jiangxi = new AtomicReference<>(0);
        AtomicReference<Integer> shandong = new AtomicReference<>(0);
        AtomicReference<Integer> henan = new AtomicReference<>(0);
        AtomicReference<Integer> hubei = new AtomicReference<>(0);
        AtomicReference<Integer> hunan = new AtomicReference<>(0);
        AtomicReference<Integer> guangdong = new AtomicReference<>(0);
        AtomicReference<Integer> guangxi = new AtomicReference<>(0);
        AtomicReference<Integer> hainan = new AtomicReference<>(0);
        AtomicReference<Integer> chongqing = new AtomicReference<>(0);
        AtomicReference<Integer> sichuan = new AtomicReference<>(0);
        AtomicReference<Integer> guizhou = new AtomicReference<>(0);
        AtomicReference<Integer> yunnan = new AtomicReference<>(0);
        AtomicReference<Integer> xizang = new AtomicReference<>(0);
        AtomicReference<Integer> shanxi = new AtomicReference<>(0);
        AtomicReference<Integer> gansu = new AtomicReference<>(0);
        AtomicReference<Integer> qinghai = new AtomicReference<>(0);
        AtomicReference<Integer> ningxia = new AtomicReference<>(0);
        AtomicReference<Integer> xinjiang = new AtomicReference<>(0);
        AtomicReference<Integer> taiwan = new AtomicReference<>(0);
        AtomicReference<Integer> xianggang = new AtomicReference<>(0);
        AtomicReference<Integer> aomen = new AtomicReference<>(0);
        AtomicReference<Integer> qita = new AtomicReference<>(0);
        if(!CollectionUtils.isEmpty(list)) {
	        list.forEach(item -> {
	            //根据身份证计算年龄，周岁
	            item.setAge(IDCardUtil.getPersonAgeFromIdCard(item.getCredentialNo()));
	            //年龄统计
	            if (item.getAge() >= 18 && item.getAge() <= 30) {
	                age1.getAndSet(age1.get() + 1);
	            } else if (item.getAge() >= 1 && item.getAge() <= 40) {
	                age2.getAndSet(age2.get() + 1);
	            } else if (item.getAge() >= 41 && item.getAge() <= 50) {
	                age3.getAndSet(age3.get() + 1);
	            } else if (item.getAge() >= 51 && item.getAge() <= 60) {
	                age4.getAndSet(age4.get() + 1);
	            }
	
	            //户籍比例
	            if (StringUtils.isEmpty(item.getPeopleType())) {
	                wl.getAndSet(wl.get() + 1);
	            } else if (item.getPeopleType().equals("1")) {
	                hj.getAndSet(hj.get() + 1);
	            } else if (item.getPeopleType().equals("2")) {
	                jw.getAndSet(jw.get() + 1);
	            }
	
	            //性别比例
	            if (item.getSex().equals("男")) {
	                man.getAndSet(man.get() + 1);
	            } else if (item.getSex().equals("女")) {
	                woman.getAndSet(woman.get() + 1);
	            } else {
	                other.getAndSet(other.get() + 1);
	            }
	
	            //省份
	            String provinceId = null;
	            if (StringUtils.isNotBlank(item.getCredentialNo())) {
	                provinceId = item.getCredentialNo().substring(0, 2);
	            }
	
	            Set<String> key = this.cityCodeMap.keySet();
	            for (String id : key) {
	                if (id.equals(provinceId)) {
	                    item.setProvince(this.cityCodeMap.get(id));
	                }
	            }
	            if (item.getProvince().equals("北京")) {
	                beijing.getAndSet(beijing.get() + 1);
	            } else if (item.getProvince().equals("天津")) {
	                tianjin.getAndSet(tianjin.get() + 1);
	            } else if (item.getProvince().equals("河北")) {
	                hebei.getAndSet(hebei.get() + 1);
	            } else if (item.getProvince().equals("山西")) {
	                shanx.getAndSet(shanx.get() + 1);
	            } else if (item.getProvince().equals("内蒙古")) {
	                nmg.getAndSet(nmg.get() + 1);
	            } else if (item.getProvince().equals("辽宁")) {
	                liaoning.getAndSet(liaoning.get() + 1);
	            } else if (item.getProvince().equals("吉林")) {
	                jilin.getAndSet(jilin.get() + 1);
	            } else if (item.getProvince().equals("黑龙江")) {
	                hlj.getAndSet(hlj.get() + 1);
	            } else if (item.getProvince().equals("上海")) {
	                shanghai.getAndSet(shanghai.get() + 1);
	            } else if (item.getProvince().equals("江苏")) {
	                jiangsu.getAndSet(jiangsu.get() + 1);
	            } else if (item.getProvince().equals("浙江")) {
	                zhejiang.getAndSet(zhejiang.get() + 1);
	            } else if (item.getProvince().equals("安徽")) {
	                anhui.getAndSet(anhui.get() + 1);
	            } else if (item.getProvince().equals("福建")) {
	                fujian.getAndSet(fujian.get() + 1);
	            } else if (item.getProvince().equals("江西")) {
	                jiangxi.getAndSet(jiangxi.get() + 1);
	            } else if (item.getProvince().equals("山东")) {
	                shandong.getAndSet(shandong.get() + 1);
	            } else if (item.getProvince().equals("河南")) {
	                henan.getAndSet(henan.get() + 1);
	            } else if (item.getProvince().equals("湖北")) {
	                hubei.getAndSet(hubei.get() + 1);
	            } else if (item.getProvince().equals("湖南")) {
	                hunan.getAndSet(hunan.get() + 1);
	            } else if (item.getProvince().equals("广东")) {
	                guangdong.getAndSet(guangdong.get() + 1);
	            } else if (item.getProvince().equals("广西")) {
	                guangxi.getAndSet(guangxi.get() + 1);
	            } else if (item.getProvince().equals("海南")) {
	                hainan.getAndSet(hainan.get() + 1);
	            } else if (item.getProvince().equals("重庆")) {
	                chongqing.getAndSet(chongqing.get() + 1);
	            } else if (item.getProvince().equals("四川")) {
	                sichuan.getAndSet(sichuan.get() + 1);
	            } else if (item.getProvince().equals("贵州")) {
	                guizhou.getAndSet(guizhou.get() + 1);
	            } else if (item.getProvince().equals("云南")) {
	                yunnan.getAndSet(yunnan.get() + 1);
	            } else if (item.getProvince().equals("西藏")) {
	                xizang.getAndSet(xizang.get() + 1);
	            } else if (item.getProvince().equals("陕西")) {
	                shanxi.getAndSet(shanxi.get() + 1);
	            } else if (item.getProvince().equals("甘肃")) {
	                gansu.getAndSet(gansu.get() + 1);
	            } else if (item.getProvince().equals("青海")) {
	                qinghai.getAndSet(qinghai.get() + 1);
	            } else if (item.getProvince().equals("宁夏")) {
	                ningxia.getAndSet(ningxia.get() + 1);
	            } else if (item.getProvince().equals("新建")) {
	                xinjiang.getAndSet(xinjiang.get() + 1);
	            } else if (item.getProvince().equals("台湾")) {
	                taiwan.getAndSet(taiwan.get() + 1);
	            } else if (item.getProvince().equals("香港")) {
	                xianggang.getAndSet(xianggang.get() + 1);
	            } else if (item.getProvince().equals("澳门")) {
	                aomen.getAndSet(aomen.get() + 1);
	            } else if (item.getProvince().equals("国外")) {
	                qita.getAndSet(qinghai.get() + 1);
	            }
	        });
        }
        //年龄
        map = new HashMap<>(16);
        map.put("age1", age1);
        map.put("age2", age2);
        map.put("age3", age3);
        map.put("age4", age4);
        resultMap.put("ageRecord", map);
        //户籍
        mapList = new ArrayList<>();
        map = new HashMap<>(16);
        map.put("name", "户籍人员");
        map.put("num", hj);
        mapList.add(map);
        map = new HashMap<>(16);
        map.put("name", "外来人员");
        map.put("num", wl);
        mapList.add(map);
        map = new HashMap<>(16);
        map.put("name", "境外人员");
        map.put("num", jw);
        mapList.add(map);
        resultMap.put("peopleTypeRecord", mapList);
        //性别
        mapList = new ArrayList<>();
        map = new HashMap<>(16);
        map.put("name", "男");
        map.put("num", man);
        mapList.add(map);
        map = new HashMap<>(16);
        map.put("name", "女");
        map.put("num", woman);
        mapList.add(map);
        map = new HashMap<>(16);
        map.put("name", "未知");
        map.put("num", other);
        mapList.add(map);
        resultMap.put("sexRecord", mapList);

        //省份
        map = new HashMap<>(50);
        map.put("北京", beijing);
        map.put("天津", tianjin);
        map.put("河北", hebei);
        map.put("山西", shanx);
        map.put("内蒙古", nmg);
        map.put("辽宁", liaoning);
        map.put("吉林", jilin);
        map.put("黑龙江", hlj);
        map.put("上海", shanghai);
        map.put("江苏", jiangsu);
        map.put("浙江", zhejiang);
        map.put("安徽", anhui);
        map.put("福建", fujian);
        map.put("江西", jiangxi);
        map.put("山东", shandong);
        map.put("河南", henan);
        map.put("湖北", hubei);
        map.put("湖南", hunan);
        map.put("广东", guangdong);
        map.put("广西", guangxi);
        map.put("海南", henan);
        map.put("重庆", chongqing);
        map.put("四川", sichuan);
        map.put("贵州", guizhou);
        map.put("云南", yunnan);
        map.put("西藏", xizang);
        map.put("陕西", shanxi);
        map.put("甘肃", gansu);
        map.put("青海", qinghai);
        map.put("宁夏", ningxia);
        map.put("新疆", xinjiang);
        map.put("台湾", taiwan);
        map.put("香港", xianggang);
        map.put("澳门", aomen);
        map.put("其他", qita);
        resultMap.put("provinceRecord", map);

        return resultMap;

    }

    private Map<String, String> cityCodeMap = new HashMap<String, String>() {
        {
            this.put("11", "北京");
            this.put("12", "天津");
            this.put("13", "河北");
            this.put("14", "山西");
            this.put("15", "内蒙古");
            this.put("21", "辽宁");
            this.put("22", "吉林");
            this.put("23", "黑龙江");
            this.put("31", "上海");
            this.put("32", "江苏");
            this.put("33", "浙江");
            this.put("34", "安徽");
            this.put("35", "福建");
            this.put("36", "江西");
            this.put("37", "山东");
            this.put("41", "河南");
            this.put("42", "湖北");
            this.put("43", "湖南");
            this.put("44", "广东");
            this.put("45", "广西");
            this.put("46", "海南");
            this.put("50", "重庆");
            this.put("51", "四川");
            this.put("52", "贵州");
            this.put("53", "云南");
            this.put("54", "西藏");
            this.put("61", "陕西");
            this.put("62", "甘肃");
            this.put("63", "青海");
            this.put("64", "宁夏");
            this.put("65", "新疆");
            this.put("71", "台湾");
            this.put("81", "香港");
            this.put("82", "澳门");
            this.put("91", "国外");
        }
    };

    @Override
    public Map<String, Object> countCompany(Map<String, Object> params, String groupId) {
        Map<String, Object> map = null;
        List<RealCompany> list = null;
        List<Map<String, Object>> resultList = new ArrayList<>();
        Map<String,Object> resultMap = new HashMap<>(2);
        if (groupId.equals("1")) {
            list = realCompanyDao.countCompanyNature(params);
        } else {
            list = realCompanyDao.countCompanyType(params);
        }
        for (RealCompany item : list) {
            map = new HashMap<>(2);
            map.put("name", item.getCompanyName());
            map.put("num", item.getCount());
            resultList.add(map);
        }
        resultMap.put("list",resultList);
        return resultMap;
    }

    @Override
    public Integer getRealCompanyCount() {
        return realCompanyDao.getRealCompanyCount();
    }
}
